package second;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * AOP联盟<br>
 * 方法拦截起,即作前拦截，又作后拦截
 * 
 * @author Wangpeihu
 * @team [Never give up]
 * @since JDK1.6(建议)
 * @date 2010-2-8
 */
public class TimeAdvice implements MethodInterceptor {

	/**
	 * 可以修改返回值
	 */
	public Object invoke(MethodInvocation mi) throws Throwable {

		long startTime = System.nanoTime();

		// 它决定目标方法是否被调用
		Object result = mi.proceed();

		long endTime = System.nanoTime();

		String m = mi.getMethod().getName();
		System.out.println(m + "方法运行了" + (endTime - startTime) + "纳秒");
		return result;
	}
}
